{extend name="public:layout" /}
{block name="title"}代码编辑{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 模板编辑</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="row toolbar">
                <div class="pull-left">
                    <a href="javascript:;" onclick="createFile(this);" class="btn btn-info"
                       data-filepath="{$path}" data-type="fold" data-url="{:url('createFile')}">新建目录</a>
                    <a href="javascript:;" onclick="createFile(this);" class="btn btn-warning"
                       data-filepath="{$path}" data-type="file" data-url="{:url('createFile')}">新建文件</a>
                    {notempty name="Request.param.path"}
                    <a href="javascript:;" onclick="back();" class="btn btn-white">返回</a>
                    {/notempty}
                </div>
                <div class="pull-right">
                    <a class="btn btn-white">当前路径：{$path}</a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="row">
                {foreach $list as $k=>$v}
                {eq name="v.type" value="dir"}
                <div class="file-box">
                    <div class="file">
                        <a href="{:url('index',['path'=>$v['path']])}">
                            <span class="corner"></span>
                            <div class="icon"><i class="fa fa-folder"></i></div>
                            <div class="file-name">
                                {$v.basename}
                                <a href="javascript:;" onclick="delFile(this);" class="pull-right"
                                   data-file="{$v.path}" data-type="fold" data-url="{:url('delFile')}">删除</a>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                    </div>
                </div>
                {else/}
                <div class="file-box">
                    <div class="file">
                        {in name="v.extension" value="jpg,png,gif,bmp"}
                        <a href="javascript:;">
                            <span class="corner"></span>
                            <div class="icon"><img src="/{$v.path}" /></div>
                            <div class="file-name">
                                {:msubstr($v['basename'],0,15)}
                                <a href="javascript:;" onclick="delFile(this);" class="pull-right"
                                   data-file="{$v.path}" data-type="file" data-url="{:url('delFile')}">删除</a>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                        {else/}
                        <a href="{:url('edit',['filename'=>$v['path']])}">
                            <span class="corner"></span>
                            <div class="icon"><i class="fa fa-file"></i></div>
                            <div class="file-name">
                                {$v.basename}
                                <a href="javascript:;" onclick="delFile(this);" class="pull-right"
                                   data-file="{$v.path}" data-type="file" data-url="{:url('delFile')}">删除</a>
                                <div class="clearfix"></div>
                            </div>
                        </a>
                        {/in}
                    </div>
                </div>
                {/eq}
                {/foreach}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    function createFile(obj){
        var url = $(obj).data('url');
        var filepath = $(obj).data('filepath');
        var type = $(obj).data('type');
        var lbl = '文件名';
        if(type=='fold'){
            lbl = '目录名';
        }
        top.layer.prompt({title: '请输入要新建的'+lbl, formType: 0}, function(file, index){
            top.layer.close(index);
            var filename = filepath+'/'+file;
            $.post(url,{filename:filename,type:type},function(res){
                if(res.code==1){
                    rePage();
                }else{
                    top.layer.alert(res.msg);
                }
            });
        });
    }
    function delFile(obj) {
        var url = $(obj).data('url');
        var file = $(obj).data('file');
        var type = $(obj).data('type');
        top.layer.confirm('请谨慎操作<br/>确认删除吗？', {icon: 3, title:'提示'}, function(index){
            top.layer.close(index);
            $.post(url,{file:file,type:type},function(res){
                if(res.code==1){
                    rePage();
                }else{
                    top.layer.alert(res.msg);
                }
            });
        });
    }
</script>
{/block}